//
//  FootPrintDateTableViewCell.swift
//  Pods
//
//  Created by eme on 2017/3/31.
//
//

import UIKit

class FootPrintDateTableViewCell: UITableViewCell {
    
    @IBOutlet weak var dateLabel: UILabel!
    @IBOutlet weak var isClicked: UIImageView!
    @IBOutlet weak var headerButton: UIButton!
    @IBOutlet weak var leftwithImage: NSLayoutConstraint!
    
    var item:FootPrintModel?{
        didSet{
            if let model = item{
                let time = Date()
                //现在时间需要特殊处理所以创建两个 NSDateFormatter
                let dateFomatterNow = DateFormatter()
                dateFomatterNow.locale = Locale(identifier: "en_US_POSIX")
                dateFomatterNow.dateStyle = .medium
                dateFomatterNow.timeZone = TimeZone(abbreviation: "GMT+8:00")
                dateFomatterNow.dateFormat = "yyyy-MM-dd"
                let nowDateStr = dateFomatterNow.string(from: time)
                let nowDate = dateFomatterNow.date(from: nowDateStr)
                let D_DAY = 86400
                let get_time = dateFomatterNow.date(from: model.time)
                
                let interval: TimeInterval = nowDate!.timeIntervalSince(get_time!)
                let days = (Int(interval)) / D_DAY
                
                if get_time == nowDate{
                    self.dateLabel.text = "今天"
                }else{
                    if days == 1 && get_time! < nowDate!{
                        self.dateLabel.text = "昨天"
                    }else if days == 2 && get_time! < nowDate!{
                        self.dateLabel.text = "前天"
                    }else{
                        self.dateLabel.text = model.time
                    }
                    
                }
            }
        }
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        self.dateLabel.normal_fontSize(15)
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
